<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="http://xmlns.heustics.org/schema/myelin/0.1/" 
  xmlns:fhttp="http://xmlns.4suite.org/4ss/http"
  xmlns:email="http://xmlns.4suite.org/4ss/modules/e-mail"
  xmlns:xf="http://www.w3.org/2002/xforms"
  xmlns:p="http://xmlns.heustics.org/schema/myelin/0.1/AgentAccount#"
  xmlns:u="http://xmlns.heustics.org/schema/myelin/0.1/UserAccount#"
  xmlns:o="http://xmlns.heustics.org/schema/myelin/0.1/UserAccount#new"
  xmlns:str="http://exslt.org/strings"
  extension-element-prefixes="fhttp email str"
  exclude-result-prefixes="xsl a l fhttp email xf o u p str"
>  
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;UserAccount#new')"/>
  <xsl:variable name="o:titles-l10n" select="$o:l10n/l:context[@name='titles']/*"/> 
  
  <xsl:template match="a:title[@key='new-user']" mode="a:head-content">
    <xsl:call-template name="a:head-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template match="a:title[@key='new-user']" mode="a:page-header">
    <xsl:call-template name="a:page-header-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>     
  
  <xsl:template match="a:data-uri" mode="a:input-show"/>
  
  <xsl:template match="a:nick" mode="a:input-show"> 
    <xsl:call-template name="p:nick-input">
      <xsl:with-param name="params-l10n" select="$u:params-l10n"/>
      <xsl:with-param name="hints-l10n" select="$u:hints-l10n"/>
    </xsl:call-template>
  </xsl:template>  
  
  <xsl:template match="a:form[@mode='main' and @status='commit-success']">
    <xsl:param name="config" select="/*/a:config"/>
    <xsl:variable name="email-l10n" select="$o:l10n/l:context[@name='account-activated-email']/*"/>
    <xsl:variable name="model" select="xf:model"/>
    <xsl:variable name="inst" select="$model/xf:instance/*"/>
    <email:send-mail 
      to="{$inst/a:agent/a:nick} &lt;{substring($inst/a:agent/a:mbox/@uri,8)}&gt;"
      from="{$config/@email-from}"
      subject="{$email-l10n[1]}"
      method="html"
      media-type="text/html"
      server="{$config/@smtp-gateway}">          
      <html>
        <body>        
          <xsl:apply-templates select="$inst" mode='a:account-activated-email-body'>          
            <xsl:with-param name="email-l10n" select="$email-l10n"/>
          </xsl:apply-templates>
        </body>
      </html>     
    </email:send-mail>
    <xsl:call-template name="o:commit-success">
      <xsl:with-param name="config" select="$config"/>
      <xsl:with-param name="model" select="$model"/>
      <xsl:with-param name="inst" select="$inst"/>
    </xsl:call-template>
  </xsl:template> 
  
  <xsl:template name="o:commit-success">
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='commit-success']/*"/>
    <xsl:param name="model" select="xf:model[1]"/>
    <xsl:param name="inst" select="$model/xf:instance[1]/*"/> 
    <div class='node_request_form {@action}'>    
      <h3> 
        <span>  
          <xsl:value-of select="$l10n[@key='title']"/>
          <em><xsl:value-of select="concat($inst/a:agent/a:nick, '@', $inst/a:memberships/a:domain/@selected)"/></em>
        </span>
      </h3>      
      <p>        
        <xsl:value-of select="$l10n[@key='description']"/>
      </p>
      <div class="cancel">
        <a href="{a:format-repeat-request(@target-action,@target)}">
          <xsl:value-of select="$l10n[@key='return']"/>
        </a>
      </div>       
      <div class="spacer"/>
    </div>    
  </xsl:template>  
  
  <xsl:template match="a:*" mode="a:account-activated-email-body">   
    <xsl:param name="email-l10n"/> 
    <xsl:param name="config" select="/*/a:config"/>   
    <xsl:variable name="agent" select="a:agent"/>
    <p><xsl:value-of select="concat($email-l10n[2],$agent/a:name)"/></p>
    <p><xsl:value-of select="$email-l10n[3]"/></p>
    <ul>
      <li><xsl:value-of select="concat($email-l10n[4],$agent/a:nick)"/></li>
      <li><xsl:value-of select="concat($email-l10n[5],$agent/a:password)"/></li>
    </ul>
    <p>
      <xsl:value-of select="$email-l10n[6]"/>     
    </p>   
    <p>
      <xsl:variable name="link" select="a:format-url-min(a:public-url-full-secure($config/@root-uri),'login')"/>
      <a href='{$link}'>
        <xsl:value-of select="$link"/>
      </a>
    </p>
  </xsl:template>
    
  
</xsl:stylesheet>

